<?php

/*
 * litchicms
 * Copyright (C) 2010-5-26 Author: tiefa(539247@qq.com)
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
!defined('BRK') && exit("!");

$can_action = array('show', 'update', 'del');
check_rights_by_id(19);
if (empty($_POST['action']))
    !empty($RT['v']['listac']) && $_POST['action'] = $RT['v']['listac'];

if (!in_array($_POST['action'], $can_action)) {
    $_POST['action'] = 'show';
}


switch ($_POST['action']) {
    case 'show':
        $GROUP = brk_get_group();
        $USER = array();
        $rs = brk_select('users', 'user_id,user_login,user_nicename,group_id', 'WHERE user_id>1');
        while ($row = $Db->fetch_array($rs)) {
            $USER[] = $row;
        }

        break;
    case 'update':
        //修改默认首页
        if (array_key_exists('thisisindex', $_POST)) {
            brk_bglog("修改默认首页为" . $_POST['thisisindex']);
            if (brk_update(
                            "settings",
                            array("set_value" => $_POST['thisisindex']),
                            "WHERE set_key='defualt_channel'")) {
                $BRK_MSG[1][] = "修改默认首页 成功!";
                $BRK_MSG[0] = 1;
            } else {
                $BRK_MSG[1][] = "修改默认首页 失败! SQL语句错误";
                $BRK_MSG[0] = 0;
            }
        } else {
            $BRK_MSG[1][] = "修改默认首页 失败! 非法参数";
        }

        foreach ($_POST['cname'] as $key => $value) {
            if (empty($value)) {
                $BRK_MSG[1][] = "频道" . $key . " 为空了,不可以这样";
            } else {
                if (brk_update(
                                "channels",
                                array("cname" => $value, "navishow" => intval($_POST['navishow'][$key]), "status" => intval($_POST['status'][$key]), "sort" => intval($_POST['sort'][$key])),
                                "WHERE ename='" . $key . "'")) {
                    $BRK_MSG[1][] = "修改 $key 成功!";
                    $BRK_MSG[0] = 1;
                } else {
                    $BRK_MSG[1][] = "修改 $key 失败! SQL语句错误";
                    $BRK_MSG[0] = 0;
                }
            }
            brk_bglog("修改默认首页为" . $_POST['thisisindex']);
        }
        $BRK_MSG[2] = 0;

        // 更新site.php 缓存文件中的BRK_CHA
        brk_ceche_site(1);
        // 更新con_channels下的缓存文件
        brk_ceche_CHA();

        break;

    case 'del':
        check_rights_by_id(36);
        if (intval($RT['v']['userId']) < 10000) {
            $_POST['action'] = 'message';
            eMsg(0, "用户ID非法!", 1);
            break;
        }

        dump($BRK_USER);

        exit;

        if(brk_delete('users', "WHERE user_id='" . intval($RT['v']['userId']) . "'")){
            $_POST['action'] = 'message';
            eMsg(1, "删除用户成功!", 1);
            break;
        }

        break;
    default:
        break;
}
?>